package com.chanyachting.emall.action.aboutUs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.chanyachting.emall.domain.AboutUs;
import com.chanyachting.emall.util.RequestUtil;

public class AboutUsAction extends DispatchAction {

	
	public ActionForward show(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		String filePath=ru.getContextRealPath()+"aboutUs.jsp";
		
		ru.setAttribute("aboutus", new AboutUs(filePath));
		
		return mapping.findForward("show");
	}
	
	
	
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		String filePath=ru.getContextRealPath()+"aboutUs.jsp";
		
		if(request.getMethod().equals("POST")){
			
			AboutUs au=new AboutUs();
			
			String context=ru.getParameter("context", "");
			
			//System.out.println("--context:"+context);
			
			au.setContext(context);
			au.setPath(filePath);
			
			if(!context.trim().equals("") && au.update()){
				
				ru.setSuccessMsg();
			}else{
				
				ru.setFailMsg();
			}
			
		}
		
		ru.setAttribute("aboutus", new AboutUs(filePath));
		
		return mapping.findForward("update");
	}
	
	

}
